from api.login import LoginAPI
from api.dept import DeptAPI
import config

class TestLoginAPI:
    # 初始化
    token666 = None
    dept_id = None
    def setup(self):
      self.login_api = LoginAPI()
      self.dept_api = DeptAPI()
     # 登录成功
      response = self.login_api.login(config.login_data)
      TestLoginAPI.token666 = response.json().get("data")
      print(TestLoginAPI.token666)

    # 获取组织架构列表
    def test01_get_dept_list(self):
          response = self.dept_api.get_dept_list(TestLoginAPI.token666)
          print(response.json())
          # 断言
          assert response.status_code == 200
          assert response.json().get("success") is True
          assert response.json().get("code") == 10000
          assert "成功" in response.text
    # 创建部门
    def test02_insert_dept(self):
        insert_data = {
            "name": "财务部",
            "code": "003001"
        }
        response = self.dept_api.insert_dept(TestLoginAPI.token666,insert_data)
        print(response.json())
        # 断言
        assert response.status_code == 200
        assert response.json().get("success") is True
        assert response.json().get("code") == 10000
        assert "成功" in response.text
        #提取数据
        TestLoginAPI.dept_id  = response.json().get("data").get("id")
        print(TestLoginAPI.dept_id)
    #查询部门
    def test03_select_dept(self):
        response = self.dept_api.select_dept(TestLoginAPI.token666,TestLoginAPI.dept_id )
        print(response.json())
        # 断言
        assert response.status_code == 200
        assert response.json().get("success") is True
        assert response.json().get("code") == 10000
        assert "成功" in response.text
    #修改部门
    def test04_update_dept(self):
        update_data = {
            "name": "测试部",
            "code": "007"
        }
        response = self.dept_api.update_dept(TestLoginAPI.token666, TestLoginAPI.dept_id,update_data )
        print(response.json())
        # 断言
        assert response.status_code == 200
        assert response.json().get("success") is True
        assert response.json().get("code") == 10000
        assert "成功" in response.text

    #删除部门
    def test05_delect_dept(self):
        response = self.dept_api.delete_dept(TestLoginAPI.token666, TestLoginAPI.dept_id)
        print(response.json())
        # 断言
        assert response.status_code == 200
        assert response.json().get("success") is True
        assert response.json().get("code") == 10000
        assert "成功" in response.text







